package inspire13.duckhuntroid;

import java.util.Vector;

import android.graphics.drawable.Drawable;

public class Animation 
{
	private Vector<Drawable> mImages;
	private Drawable mCurrentFrame;
	private String mName;
	private int mIndex;
	private boolean mFinished;
	private boolean mLoop;
	
	public Animation(String name, boolean loop)
	{
		mImages   = new Vector<Drawable>();
		mName     = name;
		mLoop     = loop;
		mIndex    = 0;
		mFinished = false;
		mCurrentFrame = null;
	}
	
	public String GetName()
	{
		return mName;
	}
	
	public void AddFrame(Drawable image)
	{
		mImages.add(image);
	}
	
	public void Reset()
	{
		mIndex    = 0;
		mFinished = false;	
	}
	
	public void Play()
	{
		if(mFinished)
			return;
		
		if(mLoop)
		{
			if(mIndex >= mImages.size())
				mIndex = 0;
		}
		else
		{
			if(mIndex >= mImages.size())
			{
				mFinished = true;
				mIndex = 0;
			}
		}
		
		if(mIndex < mImages.size())
			mCurrentFrame = mImages.elementAt(mIndex);
		else
			mCurrentFrame = null;
		
		mIndex++;
	}
	
	
	public Drawable CurrentFrame()
	{
		if(mFinished)
			return null;
		
		return mCurrentFrame;
	}
	

}
